layui.use(['form', 'upload'], function () {
    var form = layui.form;
    var upload = layui.upload;
    form.verify({
        media_name: function (value) {
            if (value == "") {
                return '不能为空';
            }
        },

    });
    upload.render({
        elem: '#btnupload'
        , url: '../Media/upload'
        ,exts:'jpg|png|gif|mp3|mp4|amr'
        , done: function (res) {
            if (res.code == 0) {
                $("#msg").html("上传文件<br>"+res.filename);
                $("#filename").val(res.filename);
            }
            layer.msg(res.message)
        }
    });
    //监听提交
    form.on('submit(save)', function (data) {
        $.post("../Media/save", data.field, function (ret) {
            if (ret.code == 0) {
                layer.closeAll();
                reload();
            }
            layer.msg(ret.message);
        });

        return false;
    });
    form.render();
});